#include <iostream>
#include <vector>
#include <cstdio> 

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int >  vec;
typedef pair < int , int > pii;

int read() {
  int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
  while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;

int cnt[N],mxd,n,K[N],dep[N];
vec G[N];

void dfs(int x,int p) {
    dep[x] = dep[p] + 1; cnt[dep[x]]++; mxd = max(mxd,dep[x]);
    for(auto y : G[x]) if(y ^ p) dfs(y,x);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin); freopen("1_bf.out","w",stdout);
#endif
    n = in; for(int i = 1;i <= n;i++) K[i] = n - in;
    for(int i = 1,u,v;i < n;i++) u = in,v = in,G[u].pb(v),G[v].pb(u);
    dep[0] = - 1;
    for(int i = 1;i <= n;i++) {
	mxd = 0; dfs(i,0); int s = 0; for(int j = 0;j <= mxd + 1;j++) { s += cnt[j]; if(s > K[i]) { printf("%d ",j - 1); break; } }
	for(int j = 0;j <= mxd;j++) cnt[j] = 0;
    } puts("");
} 
